﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.RBACs;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace RBAC.Write.API.Applications.PermissionsFiles
{
    public class LoginHander : IRequestHandler<LoginCommand, ResultsDTO>
    {
        private readonly IBateRepository<Users> user;

        public LoginHander(IBateRepository<Users> user)
        {
            this.user = user;
        }

        public async Task<ResultsDTO> Handle(LoginCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ResultsDTO res = new ResultsDTO() { Code = 0 };
                Users users=new Users();
                DapperHelper dapperHelper = new DapperHelper();
                string sql = $"select * from User where UserName='{request.UserName}' and PassWord='{request.PassWord}'";

                res.Code = user.GetAll(sql, users, dapperHelper.RBACWrite).ToList().Count();
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
